package com.twu.biblioteca.controller;

import com.twu.biblioteca.model.menu.Command;
import com.twu.biblioteca.model.menu.Menu;
import com.twu.biblioteca.view.UI;

public class BibliotecaController {

    private final UI view;
    private final Menu menu;

    public BibliotecaController(Menu menu, UI view) {
        this.menu = menu;
        this.view = view;
    }

    public void start() {
        view.welcome();
        view.showOptions();
        menu.setRunning(true);
        while (menu.isRunning()) {
            Command option = view.getCommand();
            if (option != null) {
                boolean success = menu.selectCommand(option, view.getQuestionAnswers(option));
                view.updateAfterAction(option, success);
            }
        }
    }

}
